package com.xlh.controller;

import com.xlh.common.Result;
import com.xlh.param.Base64Param;
import com.xlh.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhr 2019/3/14
 */
@Api("Markdown编辑器上传图片")
@RestController
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @ApiOperation("上传图片")
    @PostMapping("/markdown/picture")
    public Result<String> uploadMarkdownPicture(@RequestParam("image") MultipartFile image) {
        return Result.success(resourceService.uploadMarkdownPicture(image));
    }

    @ApiOperation("将图片保存为文件存放至服务器")
    @PostMapping("/base64/file-save")
    public Result<String> savePictureAsFile(@RequestBody Base64Param base64Param) {
        return Result.success(resourceService.savePictureAsFile(base64Param.getBase64Info()));
    }
}
